home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / plugin.e < prev    next >
Encoding:
Text File  |  1999-06-30  |  5.3 KB  |  272 lines

  1. /* ******** */
  2. /* plugin.e */
  3. /* ******** */
  4.  
  5.  
  6.  
  7. /*
  8.     WBBump - Bumpmapping on the Workbench!
  9.  
  10.     Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software Foundation,
  24.     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26.  
  27.  
  28. OPT MODULE
  29.  
  30.  
  31. MODULE    'exec/nodes',
  32.         'exec/libraries',
  33.  
  34.         'utility/tagitem'
  35.  
  36.  
  37. MODULE    '*wbbump_plugin',
  38.         '*plugin_const',
  39.         '*errors'
  40.  
  41.  
  42.  
  43.  
  44.  
  45. EXPORT OBJECT plugin
  46. PRIVATE
  47.     libbase        :    PTR TO lib
  48.     filename    :    PTR TO CHAR
  49.     instance    :    LONG
  50.     outbuf        :    PTR TO CHAR
  51. ENDOBJECT
  52.  
  53.  
  54.  
  55. /* constructor */
  56.  
  57. PROC plugin(copyfrom=NIL:PTR TO plugin) OF plugin
  58.     IF copyfrom
  59.         self.libbase := copyfrom.libbase
  60.         self.filename := copyfrom.filename
  61.         self.instance := NIL
  62.     ELSE
  63.         self.libbase := NIL
  64.         self.filename := NIL
  65.         self.instance := 0
  66.     ENDIF
  67. ENDPROC
  68.  
  69.  
  70. /* loads and initializes the plugin */
  71. PROC load(pluginname, minver=1) OF plugin HANDLE
  72.     DEF    lib
  73.  
  74.     self.plugin()
  75.  
  76.     self.filename := String(StrLen(pluginname)+1)
  77.     StrCopy(self.filename, pluginname)
  78.  
  79.     IF (lib := OpenLibrary(self.filename, minver)) = NIL THEN Raise(-1)
  80.  
  81.     self.libbase := lib
  82.  
  83.     wbbump_pluginbase := self.libbase
  84.  
  85.     IF PluginInit(NIL) = FALSE THEN Raise(-1)
  86.  
  87. EXCEPT DO
  88.     IF exception THEN RETURN FALSE
  89. ENDPROC TRUE
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /* create an instance of the class */
  96.  
  97. PROC createInstance(tags=NIL:PTR TO tagitem) OF plugin HANDLE
  98.     DEF    newinstance=NIL:PTR TO plugin
  99.  
  100.     NEW newinstance.plugin(self)    -> copy our attrs
  101.  
  102.     IF newinstance.initInstance(tags) = FALSE THEN Raise(-1)
  103.  
  104.     newinstance.outbuf := NewR(newinstance.getWidth() * newinstance.getHeight())
  105.  
  106. EXCEPT DO
  107.     IF exception
  108.         END newinstance
  109.         RETURN NIL
  110.     ENDIF
  111. ENDPROC newinstance
  112.  
  113.  
  114. /* init rutine used in createInstance() */
  115.  
  116. PROC initInstance(tags=NIL:PTR TO tagitem) OF plugin HANDLE
  117.     DEF instance=NIL
  118.  
  119.     wbbump_pluginbase := self.libbase
  120.  
  121.     IF (instance := PluginInitInstance(tags)) = NIL THEN Raise(-1)
  122.  
  123.     self.instance := instance
  124.  
  125. EXCEPT DO
  126.     IF exception
  127.         self.libbase := NIL
  128.         RETURN FALSE
  129.     ENDIF
  130. ENDPROC TRUE
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. /* get a plugin attr (PLUGINTAG_xxx with [  G ]) */
  138. PROC getAttr(attr) OF plugin
  139.     DEF res
  140.  
  141.     wbbump_pluginbase := self.libbase
  142.  
  143.     IF wbbump_pluginbase=NIL THEN RETURN NIL
  144.  
  145.     IF PluginGetAttr(self.instance, attr, {res}) = FALSE THEN RETURN 0, FALSE
  146.  
  147. ENDPROC res, TRUE
  148.  
  149.  
  150.  
  151. /* is this the "class" handler or an instance? */
  152. PROC isClass() OF plugin IS IF self.instance THEN FALSE ELSE TRUE
  153.  
  154.  
  155. /* is the plugin a modifier? */
  156. PROC isModifier() OF plugin IS self.getAttr(PLUGINTAG_ISMODIFIER)
  157.  
  158.  
  159. /* get the type of plugin */
  160. PROC getType() OF plugin IS self.getAttr(PLUGINTAG_TYPE)
  161.  
  162.  
  163. /* get width of plugin */
  164. PROC getWidth() OF plugin IS self.getAttr(PLUGINTAG_WIDTH)
  165.  
  166. /* get height of plugin */
  167. PROC getHeight() OF plugin IS self.getAttr(PLUGINTAG_HEIGHT)
  168.  
  169.  
  170. /* get the name of the plugin */
  171. PROC getName() OF plugin IS self.getAttr(PLUGINTAG_NAME)
  172.  
  173.  
  174. /* get the tooltypes command that activates this plugin */
  175. PROC getCommandName() OF plugin IS self.getAttr(PLUGINTAG_COMMANDNAME)
  176.  
  177.  
  178. /* get isstatic attribute */
  179. PROC isStatic() OF plugin IS self.getAttr(PLUGINTAG_ISSTATIC)
  180.  
  181.  
  182. /* get NeedUpdate attribute */
  183. PROC needUpdate() OF plugin IS self.getAttr(PLUGINTAG_NEEDUPDATE)
  184.  
  185.  
  186. /* get the output buffer */
  187. PROC getOutBuf() OF plugin IS self.outbuf
  188.  
  189.  
  190. /* get copyright info */
  191. PROC getCopyright() OF plugin IS self.getAttr(PLUGINTAG_COPYRIGHT)
  192.  
  193.  
  194. /* get the author name / email */
  195. PROC getAuthor() OF plugin IS self.getAttr(PLUGINTAG_AUTHOR)
  196.  
  197.  
  198. /* get the plugin description */
  199. PROC getDescription() OF plugin IS self.getAttr(PLUGINTAG_DESC)
  200.  
  201.  
  202. /* get the author name / email */
  203. PROC getLastError() OF plugin IS self.getAttr(PLUGINTAG_LASTERROR)
  204.  
  205.  
  206. /* do the action! */
  207. PROC doAction(inbuf, tags=NIL:PTR TO tagitem) OF plugin
  208.     DEF    res
  209.  
  210.     wbbump_pluginbase := self.libbase
  211.  
  212.     res := PluginDoAction(self.instance, inbuf, self.outbuf, tags)
  213.  
  214. ENDPROC res
  215.  
  216.  
  217.  
  218.  
  219. /* debug function */
  220. PROC writeinfo() OF plugin
  221.     WriteF(    '  Instance  Plugin name                   modifier  class     type commandname         size\n'+
  222.             '  \l$\z\h[8] \s[30]\s[10]\s[10]\d[5]\s[20]\d[3]x\d[3]\n',
  223.             self.instance,
  224.             self.getName(),
  225.             IF self.isModifier() THEN '*' ELSE ' ',
  226.             IF self.isClass() THEN '*' ELSE ' ',
  227.             self.getType(),
  228.             self.getCommandName(),
  229.             self.getWidth(),
  230.             self.getHeight())
  231. ENDPROC
  232.  
  233.  
  234. /* close and free all plugin resources */
  235. PROC end() OF plugin
  236.     self.freeall()
  237. ENDPROC
  238.  
  239.  
  240. /* close and free all plugin resources */
  241. PROC freeall() OF plugin
  242.  
  243.     wbbump_pluginbase := self.libbase
  244.  
  245.     IF self.libbase
  246.  
  247.         IF self.instance
  248.             PluginFreeInstance(self.instance)
  249.         ELSE
  250.             PluginCleanup()                -> cleanup rutine in plugin
  251.             CloseLibrary(self.libbase)
  252.  
  253.             IF self.libbase.opencnt = 0
  254.                 RemLibrary(self.libbase)    -> flush library if opencount = 0
  255.             ENDIF
  256.  
  257.         ENDIF
  258.  
  259.     ENDIF
  260.  
  261.     IF self.outbuf THEN Dispose(self.outbuf)
  262.  
  263.     self.filename := NIL
  264.     self.libbase := NIL
  265.     self.instance := NIL
  266.     self.outbuf := NIL
  267.  
  268.  
  269. ENDPROC
  270.  
  271.  
  272.